package com.yer.note.activity;

import static com.yer.note.entity.User.user;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.yer.note.R;
import com.yer.note.entity.User;

public class setting_password extends AppCompatActivity {
    Button submit;
    Button cancel;
    public void initView(){
        submit = findViewById(R.id.setpassword_btn_commit);
        cancel = findViewById(R.id.setpassword_btn_cancel);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_password);
        initView();
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText old = findViewById(R.id.setpassword_input_old);
                EditText New = findViewById(R.id.setpassword_input_new);
                EditText NewAgain = findViewById(R.id.setpassword_input_new_again);
                String pwd_old = old.getText().toString();
                String pwd_new = New.getText().toString();
                String pwd_new_again = NewAgain.getText().toString();
                if(!user.getPassword().equals(pwd_old)){
                    Toast.makeText(view.getContext(),"原密码输入错误，请重新输入",Toast.LENGTH_SHORT).show();
                }else{
                    if(!pwd_new.equals(pwd_new_again)){
                        Toast.makeText(view.getContext(),"新密码两次输入不一致，请检查一下",Toast.LENGTH_SHORT).show();
                    }else{
                        user.setPassword(pwd_new);
                        User.update(user);
                        old.setText("");
                        New.setText("");
                        NewAgain.setText("");
                    }
                }
            }
        });
    }
}